<?php
// Copyright 2011 Zeptonic Ek. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification, are
// permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
//    conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
//    of conditions and the following disclaimer in the documentation and/or other materials
//    provided with the distribution.
// 
// THIS SOFTWARE IS PROVIDED BY Zeptonic Ek ``AS IS'' AND ANY EXPRESS OR IMPLIED
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL Zeptonic Ek OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// 
// The views and conclusions contained in the software and documentation are those of the 
// authors and should not be interpreted as representing official policies, 
// either expressed or implied, of Zeptonic Ek.


/**
 * Stränghantering.
 * 
 * @category Golfscraper
 * @package  Golfscraper
 * @author   Anders Axelsson <anders@zeptonic.com>
 * @author   Mattias Tiger <mattias@zeptonic.com>
 * @link     http://www.zeptonic.com
 */
class String {
	/**
	 * Returnerar sant eller falskt beroende på om en delsträng tills i en annan.
	 *
	 * @param String $haystack Sträng att söka i
	 * @param String $needle Sträng att söka efter
	 *
	 * @return Boolean
	 */
	public static function in_string($haystack, $needle) {
		return strpos($haystack, $needle) !== false;
	}
	
	/**
	 * Kontrollerar om en sträng startar med ett tecken eller inte.
	 *
	 * @param String $haystack Sträng att söka 
	 * @param String $needle Tecken att kontrollera om strängen startar med
	 *
	 * @return Boolean
	 */
	public static function starts_with($haystack, $needle) {
		return strpos($haystack, $needle) === 0;
	}
	
    /**
     * Returnerar den vänstra delen av en strän med 
     * utgångspunkt från den första förekomsten av en delsträng.
     * 
     * @param String $s1 Sträng att hämta vänster del ur
     * @param String $s2 Delsträng som ska dela en sträng
     * 
     * @return String
     */
	public static function left($s1, $s2) {
		return substr($s1, 0, strpos($s1, $s2));
	}
}

?>